package main

import (
	"fmt"
	"encoding/json"
)

type LogEntry struct {
	ID 	int `json:"id"`
	Name string `json:"name"`
	Payload LogPayload `json:"payload`
}

type LogPayload struct {
	Message string `json:"message"`
}

type fauxLogPayload LogPayload

func (lp *LogPayload) UnmarshalJSON(b []byte) error {
	var s string
	if err := json.Unmarshal(b, &s); err != nil {
		return err
	}

	var f fauxLogPayload
	if err := json.Unmarshal([]byte(s), &f); err != nil {
		return err
	}

	*lp = LogPayload(f)
	return nil
}

func main() {
	doc := []byte(`{"id":12345, "name": "Test Document", "payload": "{\"message\":\"test\"}"}`)
	var entry LogEntry
	if err := json.Unmarshal(doc, &entry); err != nil {
		fmt.Println("Error!", err)
	}

	fmt.Printf("%v", entry)
}